﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

namespace Directory.Web
{
	public partial class Admin_ReplyMessage : System.Web.UI.Page
	{
		int id = 0;
		string p = string.Empty;
		protected void Page_Load(object sender, EventArgs e)
		{
			try
			{
				p = Request.QueryString["p"];
			}
			catch
			{
			}
			try
			{
				id = int.Parse(Request.QueryString["id"].Trim());
			}
			catch
			{
				Server.Transfer("messagemanage.aspx?page=" + p);
				return;
			}
			if (!IsPostBack)
			{
				Directory.Model.MessageInfo msg = MessageBoardDataProxy.GetMessageInfo(id);
				lbTitle.Text = msg.Title + "&nbsp;&nbsp;作者：" + msg.Author + "&nbsp;&nbsp;时间：" + msg.ReleaseDate.ToString() + "&nbsp;&nbsp;IP：" + msg.AuthorIP;
				ltMessage.Text = msg.Content;
				txtReply.Text = msg.Reply;
				btnDelete.Attributes.Add("onclick", "return confirm('确认删除吗？')");
			}
		}
		//回复
		protected void btnReply_Click(object sender, EventArgs e)
		{
			string reply = string.Empty;
			try
			{
				reply = txtReply.Text.Trim();
			}
			catch
			{
			}
			try
			{
				MessageBoardDataProxy.ReplyMessage(id, Page.User.Identity.Name,reply);
				ClientScript.RegisterStartupScript(this.GetType(), null, "<script>alert('回复成功');window.location.href='messagemanage.aspx?page=" + p + "'</script>");
			}
			catch
			{
				ClientScript.RegisterStartupScript(this.GetType(), null, "<script>alert('回复失败')</script>");
			}
		}
		//删除
		protected void btnDelete_Click(object sender, EventArgs e)
		{
			try
			{
				MessageBoardDataProxy.DeleteMessage(id);
				ClientScript.RegisterStartupScript(this.GetType(), null, "<script>alert('删除成功');window.location.href='messagemanage.aspx?page=" + p + "'</script>");
			}
			catch
			{
				ClientScript.RegisterStartupScript(this.GetType(), null, "<script>alert('删除失败')</script>");
			}
		}
	}
}